package SellCar.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import SellCar.dao.user.UserMapper;
import SellCar.dao.user.impl.UserMapperImpl;
import SellCar.pojo.User;
import SellCar.service.UserBiz;
import SellCar.service.impl.UserBizImpl;

public class UserServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			this.doPost(request, response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		HttpSession session = request.getSession();
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		
		UserBiz userbiz = new UserBizImpl();
		String opr = request.getParameter("opr");
		if("login".equals(opr)){
			String userName = request.getParameter("uname");
			String password = request.getParameter("upwd");
			if(userbiz.panduan(userName, password)){
				session.setAttribute("uname", userName);
				response.sendRedirect("guide.jsp");
			}else{
				request.getRequestDispatcher("login.jsp").forward(request, response);
			}
			
		}else if("add".equals(opr)){
			String uname = request.getParameter("name");
			Integer shenfen = Integer.parseInt(request.getParameter("shenfen"));
			String pw1 = request.getParameter("pw1");
			String pw2 = request.getParameter("pw2");
			
			
			if(pw1.equals(pw2)){
				if(userbiz.panduan1(uname, pw1, shenfen)){
					response.sendRedirect("login.jsp");
					System.out.println("132132");
				}else{
					request.getRequestDispatcher("Error.jsp").forward(request, response);
				}
			}
			
		}
		
		
		
		
		
		
	}

}
